<?php

class Angka {
	public function Terbilang($angka){
					  $bilang = array(
			  1 => 'satu',
			  2 => 'dua',
			  3 => 'tiga',
			  4 => 'empat',
			  5 => 'lima',
			  6 => 'enam',
			  7 => 'tujuh',
			  8 => 'delapan',
			  9 => 'sembilan',
			  0 => 'nol',
			  ','=>'koma'
			 );
			 
			 $nilai = array(
			  0 => '',
			  1 => 'puluh',
			  2 => 'ratus',
			  3 => 'belas'
			 );
			 
			 $nilai2= array(
			  0 => '',
			  1 => 'ribu',
			  2 => 'juta',
			  3 => 'milyar',
			  4 => 'trilyun'
			  
			 );
			 
			 $angka   = str_replace('.','',$angka); //replace titik kalo ada
			 $angka  = strrev($angka);
			 $angka_ar = str_split($angka,3);
			 $bilang_ar  = array();
			 
			 foreach ($angka_ar as $key => $val){
			  $pecah3 = str_split($val);
			  
			  $pecah3_ar = array();
			  foreach($pecah3 as $pkey => $pval){
			   if($pval==0 &&  count($pecah3) > 1)
			    $pecah3_ar[$pkey] = '';
			   else if($pval==1 && $pkey == count($pecah3)-1)
			    $pecah3_ar[$pkey] = 'se'.$nilai[$pkey];
			   else
			    $pecah3_ar[$pkey] = $bilang[$pval].' '.$nilai[$pkey];
			  }
			  $bilang_ar[$key] = implode(' ',array_reverse($pecah3_ar)).$nilai2[$key];
			 }
			 return(implode(', ',array_reverse($bilang_ar)));
		   
		   
		} 
}
?>